package com.cicoding.entity.dto;/**
 * Created by Intellij IDEA.
 * User:  nuyang
 * Date:  2024/6/3
 */

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Hashtable;

/**
 * @Author: 刘明
 * @Description:
 * @Date: 2024/6/3 14:03
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Uf3sParam {

    // 自动模式开 2005
    //自动模式关 2006

    private Integer code;

    private Object data;


    //开启全自动读写模式 并且指定天线
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class DynamicStart {
        private String antennaEnable;
    }

    //设置自动模式参数
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class AutoModeBean {
        // 自动模式 0连续 1触发
        private int autoMode;
        // PC服务IP地址
        private String ip;
        // 输出模式 0串口 1socket
        private int output;
        // PC服务端口
        private String port;
        // 触发方式 0低电平 1高电平
        private int trigger;
        // 触发的电平id
        private int gpiId;
    }

    //设置天线功率
    @Data
    @AllArgsConstructor
    public static class MsgBaseSetPower {
        // 读写器对应天线功率(key：天线索引号，value：天线功率值)
        private Hashtable<Integer, Integer> dicPower;
    }

    /*
    转换成json字符串并且只包含非空字段
     */
    public String toJsonString() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 只包含非空字段
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
